﻿<%@ Page Language="C#" Inherits="System.Web.Mvc.ViewPage<dynamic>" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
    <title>方案设置</title>
    
    <script src="../../Scripts/jquery-1.4.1.js" type="text/javascript"></script>
    <link href="../../Content/Themes/blue2/css.css" rel="stylesheet" type="text/css" />
    <style type="text/css">
        .content #select1,#select2{width:100px;height:130px;border: solid 1px #abadb3;outset;padding:4px;}
        .fieldCss{border: solid 1px #C6E2FF; width: 200px; padding: 10px 10px 10px 10px;}
        .left1{ float:left; width:110px; height:140px; margin-top:10px;}
        .right{ float:left; width:64px; margin-left:3px; text-align:center; margin-top:4px;}
        .marginTop{ margin-top:2px; display:inline-block; text-align:center;}
        .inputText{width:60px; margin-top:3px; text-align:center;}
        .inputText2{width:80px; margin-top:3px; text-align:center;}
        .leftDiv{float:left; margin-top:10px;}
        .rightDiv{ margin-left:10px; float:left;margin-top:10px;}
        label.error{ color:Red;margin-left:2px}
    </style>
</head>
<body class="main">
     <div class="AllWebTopDiv">
        <div class="path">
            <div class="nav">
                <a href="#">添加消费方案</a>
            </div>
        </div>
       <div class="content" style="height:415px;">
        <div>
          <label>方案名：</label>
          <%:Html.TextBox("solutionName")%>
          <label style=" display:inline-block; margin-left:50px;">选择卡面模板：</label>
          <%:Html.DropDownList("tep")%>
        </div>
        <div class="leftDiv">
         <fieldset class="fieldCss">
                <legend>消费方案</legend>
                <div class="left1"> 
                 <%:Html.DropDownList("select1", null, new { multiple = "multiple" })%> 
                  </div>
                <div class="right">
                 <label class="marginTop">每</label>
                 <br /> 
                 <%:Html.TextBox("money", null, new { @class = "inputText" })%>
                 <label class="marginTop">元送积分</label>
                 <br /> 
                 <%:Html.TextBox("point", null, new { @class = "inputText" })%>
                 <br />
                 <input  type="button"  class="button" value="添加" onclick="add(1)" style=" margin-top:3px;"/>
                 <br />
                 <input  type="button"  class="button" value="移除" onclick="removeOption(1)" style=" margin-top:3px;"/>
                </div>
          </fieldset>
          </div>
          <div class="rightDiv">
           <fieldset class="fieldCss">
                <legend>充值方案</legend>
                <div class="left1">
                   <%:Html.DropDownList("select2", null, new { multiple = "multiple" })%> 
                  </div>
                <div class="right">
                 <label class="marginTop">每</label>
                 <br />
                  <%:Html.TextBox("Cmoney", null, new { @class = "inputText" })%>
                 <label class="marginTop">元送金额</label>
                 <br />
                  <%:Html.TextBox("Smoney", null, new { @class = "inputText" })%>
                 <br />
                 <input  type="button" class="button" value="添加" onclick="add(2)" style=" margin-top:3px;"/>
                 <br />
                 <input  type="button"  class="button" value="移除" onclick="removeOption(2)" style=" margin-top:3px;"/>
                </div>
          </fieldset>
          </div>
          <div class="leftDiv">
             <fieldset class="fieldCss">
                <legend>折扣方案</legend>
               <label>折扣率：</label>  <%:Html.TextBox("discount", null, new { @class = "inputText" })%>&nbsp;<strong>%</strong>
              </fieldset>
          </div>
          <div class="rightDiv">
             <fieldset class="fieldCss">
                <legend>延期天数</legend>
               <label>延期天：</label>  <%:Html.TextBox("day", null, new { @class = "inputText" })%>&nbsp;<strong>天</strong>
              </fieldset>
          </div>
          <div class="leftDiv">
             <fieldset class="fieldCss">
                <legend>升级条件</legend>
                <label>下一等级：</label> <%:Html.DropDownList("nextLevel")%><br/>
               <label>消费总额></label>  <%:Html.TextBox("consume", null, new { @class = "inputText2" })%>&nbsp;<strong>元</strong>
              </fieldset>
          </div>
          <br /><br />
          <div class="leftDiv" style="padding-top:10px;">
           <input  type="button" value="保存" class="button2" onclick="Save()"  style="margin-left:150px;"/>
           <input  type="button" value="关闭" onclick="closeWindows()" class="button2" style="margin-left:50px;"/>
          </div>
       </div>
    </div>
</body>
</html>
<script type="text/javascript">
   
    //添加
    function add(num) {
        reg = /^[-+]?\d*$/;
        if (parseInt(num) == 1) {
              var money = $("#money").val();
               var point= $("#point").val();
               if (!reg.test(money) || !reg.test(point)) {
                   return false;
               }
               var str = money + ',' + point;
                $("#select1").append("<option value=" + str + ">" + str + "</option>");
                $("#money").val("");
                $("#point").val("");
        }
        else {
            if (parseInt(num) == 2) {

               var Cmoney = $("#Cmoney").val();
               var Smoney= $("#Smoney").val();
               if (!reg.test(Cmoney) || !reg.test(Smoney)) {
                   return false;
               }
               var str = Cmoney + ',' + Smoney;
               $("#select2").append("<option value=" + str + ">" + str + "</option>");
               $("#Cmoney").val("");
               $("#Smoney").val("");
            }
        }
    }
    //移除
    function removeOption(num) {
        if ($('#select1 option:selected').length != 1) {
            return false;
        }
        if (parseInt(num) == 1) {
            $('#select1 option:selected').remove();
        }
        else {
            if (parseInt(num) == 2) {
                $('#select2 option:selected').remove();
            }
        }
       
    }
    $('#select1').dblclick(function () {
        $("option:selected", this).remove();
    });
    $('#select2').dblclick(function () {
        $("option:selected", this).remove();
    });

    function GetQueryString(name) {
        var reg = new RegExp("(^|&)" + name + "=([^&]*)(&|$)", "i");
        var r = window.location.search.substr(1).match(reg);
        if (r != null) return (r[2]); return null;
    }
    var Id="";
    window.onload = function choseX() {

         Id = GetQueryString("Id");
        if (Id.length>0) {
            $(".nav a").text("编辑消费方案");

        }
    }
    //保存
    function Save() {
    
        if ($('#select1').text().length <= 0) {
            alert("消费方案不能为空");
            return false;
        }
        if ($('#select2').text().length <= 0) {
            alert("充值方案不能为空");
            return false;
        }
        var consumeStr = "";
        var savingStr = "";
        $("#select1 option").each(function () {
            consumeStr += $(this).text() + "|";
        });
        $("#select2 option").each(function () {
            savingStr += $(this).text() + "|";
        });
        var solutionName = $("#solutionName").val();
        var discount = $("#discount").val();
        var consume = $("#consume").val();
        var day = $("#day").val();
        var tep = $("#tep option:selected").val();
        var nextLevel = $("#nextLevel option:selected").val();
        reg = /^[-+]?\d*$/;
        if ($("#solutionName").val().length <= 0) {
            alert("方案名不能为空");
            return false;
        }
        if (!reg.test(discount)) {
            alert("折扣率应为整数");
            return false;
        }
        if (!reg.test(day)) {
            alert("延期天应为整数");
            return false;
        }
        if (isNaN(consume)) {
            alert("消费总额应为数字");
            return false;
        }
         $.ajax({
            type:"POST",
            url:"<%:Url.Action("ConsumeSolutionSave","ConsumeSolution") %>",
            data:"consumeStr="+consumeStr+"&savingStr="+savingStr+"&solutionName="+solutionName+"&discount="+discount+"&consume="+consume+"&day="+day+"&tep="+tep+"&nextLevel="+nextLevel+"&Id="+Id+"",
            cache:false,
            success:function(html)
            {
                 alert(html);
               window.parent.location.href="<%:Url.Action("ConsumeSolution","ConsumeSolution") %>";
               closeWindows();
            }
        });
    }
    //关闭窗口
    function closeWindows() {
        var i = parent.layer.getFrameIndex();
        parent.layer.close(i);
    }
</script>
